package com.atguigu.lease.common.springmvc;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author:高尚
 * @data:2025/7/8 15:24
 * @description: 全局异常处理器
 *
 */
@RestControllerAdvice
public class GlobalExceptionHandlers {
    @ExceptionHandler(Exception.class)
    public Result<String> exceptioHandler(Exception e){
        //记录日志
        e.printStackTrace();
        //返回提示
        return Result.fail(e.getMessage());
    }

    @ExceptionHandler(LeaseException.class)
    public Result<String> exceptioHandler(LeaseException e){
        //记录日志
        e.printStackTrace();
        //返回提示
        return Result.fail(e.getCode(),e.getMessage());
    }

}
